package com.cbh.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.cbh.api.model.ApiResult;
import com.cbh.domain.service.PaywayService;
import com.cbh.entity.Payway;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(description = "支付方式管理")
@RestController
@RequestMapping("/sign/v3/pays")
public class PaywayController {
	@Autowired
	PaywayService payService;

	/**
	 * 保存支付方式信息
	 * 
	 * @param product
	 * @return
	 */
	@ApiOperation(value = "支付方式信息保存", httpMethod = "POST")
	@RequestMapping(value = "", method = RequestMethod.POST, produces = "application/json")
	public ApiResult<String> save(
			@ApiParam(value = "支付方式信息", required = true) @RequestBody(required = true) Payway payway) {
		ApiResult<String> apiResult = new ApiResult<>();
		try {
			String re = payService.save(payway);
			return apiResult.success(re);
		} catch (Exception e) {
			return apiResult.fail(e.getMessage());
		}
	}

	/**
	 * 获取全部支付方式信息
	 * 
	 * @return
	 */
	@ApiOperation(value = "获取全部支付方式信息", httpMethod = "GET")
	@RequestMapping(value = "", method = RequestMethod.GET, produces = "application/json")
	public ApiResult<List<Payway>> getAll() {
		ApiResult<List<Payway>> apiResult = new ApiResult<>();
		try {
			List<Payway> obs = payService.getAll();
			return apiResult.success(obs);
		} catch (Exception e) {
			return apiResult.fail(e.getMessage());
		}
	}

	/**
	 * 获取支付方式信息
	 * 
	 * @param proId
	 * @return
	 */
	@ApiOperation(value = "获取支付方式信息", httpMethod = "GET")
	@ApiImplicitParams({ @ApiImplicitParam(paramType = "path", name = "id", dataType = "String", required = true) })
	@RequestMapping(value = "{id}", method = RequestMethod.GET, produces = "application/json")
	public ApiResult<Payway> getOne(@PathVariable("id") String id) {
		ApiResult<Payway> apiResult = new ApiResult<>();
		try {
			Payway ob = payService.getOne(id);
			return apiResult.success(ob);
		} catch (Exception e) {
			return apiResult.fail(e.getMessage());
		}
	}
}
